package com.atguigu.ssyx.activity.controller;

import com.atguigu.ssyx.activity.service.SecKillService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.activity.Seckill;
import com.atguigu.ssyx.vo.activity.SeckillQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者:hfj
 * 功能:开发秒杀活动管理接口
 * 日期: 2024/4/27 13:49
 */
@Api(value = "SecKill管理", tags = "SecKill管理")
@RestController
@RequestMapping(value="/admin/activity/seckill")
public class SecKillController {

    @Autowired
    private SecKillService secKillService;

    /**
     *
     * @param page 当前页
     * @param limit 每页记录数
     * @param seckillQueryVo seckillQueryVo实体类
     * @return 获取分页列表
     */
    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit, SeckillQueryVo seckillQueryVo) {
        Page<Seckill> pageParam = new Page<>(page, limit);
        IPage<Seckill> pageModel = secKillService.selectPage(pageParam, seckillQueryVo);
        return Result.ok(pageModel);
    }

    /**
     *
     * @param id id
     * @return 获取
     */
    @ApiOperation(value = "获取")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Long id) {
        Seckill seckill = secKillService.getById(id);
        return Result.ok(seckill);
    }

    /**
     *
     * @param seckill seckill
     * @return 新增
     */
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody Seckill seckill) {
        secKillService.save(seckill);
        return Result.ok(null);
    }

    /**
     *
     * @param seckill seckill
     * @return 修改
     */
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public Result updateById(@RequestBody Seckill seckill) {
        secKillService.updateById(seckill);
        return Result.ok(null);
    }

    /**
     *
     * @param id id
     * @return 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        secKillService.removeById(id);
        return Result.ok(null);
    }

    /**
     *
     * @param idList idList
     * @return 根据id列表删除
     */
    @ApiOperation(value = "根据id列表删除")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        secKillService.removeByIds(idList);
        return Result.ok(null);
    }

    /**
     *
     * @param id id
     * @param status status
     * @return 更新状态
     */
    @ApiOperation(value = "更新状态")
    @PostMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        secKillService.updateStatus(id, status);
        return Result.ok(null);
    }
}
